<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import staff from '@/api/admin/staff'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (record, newValue, numberName) => {
  staff.numberOperation({ id: record.id, numberName, numberValue: newValue }).then( res => {
    if (res.success) {
      Message.success(res.message)
      record[numberName] = newValue
    }
  }).catch( e => { console.log(e) } )
}


const switchStatus = (record, statusValue, statusName) => {
  staff.changeStatus({ id: record.id, statusName, statusValue }).then( res => {
    if (res.success) {
      Message.success(res.message)
      record[statusName] = statusValue
    }
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'staff',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: staff.getList,
  // recycleApi: staff.getRecycleList,
  requestParams: { orderBy: ['id'], orderType: 'desc' },
  add: {
    show: true,
    api: staff.save,
    auth: ['admin:staff:save']
  },
  edit: {
    show: true,
    api: staff.update,
    auth: ['admin:staff:update']
  },
  delete: {
    show: true,
    api: staff.deletes,
    auth: ['admin:staff:delete'],
    realApi: staff.realDeletes,
    realAuth: ['admin:staff:realDeletes']
  },
  /*recovery: {
    show: true,
    api: staff.recoverys,
    auth: ['admin:staff:recovery']
  },
  import: {
    show: true,
    url: 'admin/staff/import',
    templateUrl: 'admin/staff/downloadTemplate',
    auth: ['admin:staff:import']
  },
  export: {
    show: true,
    url: 'admin/staff/export',
    auth: ['admin:staff:export']
  }*/
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: "密码",
    dataIndex: "password",
    formType: "input",
    extra: "留空表示不更新密码",
    hide: true,
    addRules: {
      required: true,
      message: "请输入密码"
    }
  },
  {
    title: "手机号",
    dataIndex: "phone",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入手机号"
    }
  },
  {
    title: "头像",
    dataIndex: "avatar",
    formType: "upload",
    extra: "建议尺寸xxx",
    commonRules: {
      required: true,
      message: "请输入头像"
    },
    multiple: false,
    onlyData: true,
    returnType: "url",
    chunk: false,
    type: "image"
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  }
])
</script>
<script> export default { name: 'admin:staff' } </script>
